package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.*;
import top.api.service.ClassService;
import top.api.service.UserService;

import java.util.List;

@RestController
@RequestMapping("/class")
@RequiredArgsConstructor
@Api(tags = "班级管理")
public class ClassController {
    private final ClassService baseService;

    @GetMapping
    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> pageList(@Validated PageDto pageDto, Integer id,String classname){
        return baseService.pageList(pageDto,id,classname);
    }

    @GetMapping("/{id}")
    @SaCheckRole("admin")
    @ApiOperation("查询班级详情")
    public ResUlt<?> getClassInfo(@PathVariable Integer id){
        return baseService.getClassInfo(id);
    }

    @PostMapping
    @SaCheckRole("admin")
    @ApiOperation("添加班级")
    public ResUlt<?> addClass(@RequestBody @Validated ClassAddDto classAddDto){
        return baseService.addClass(classAddDto);
    }

    @PutMapping
    @SaCheckRole("admin")
    @ApiOperation("修改班级")
    public ResUlt<?> editClass(@RequestBody @Validated ClassEditDto classEditDto){
        return baseService.editClass(classEditDto);
    }

    @DeleteMapping("/{ids}")
    @SaCheckRole("admin")
    @ApiOperation("删除班级")
    public ResUlt<?> delClass(@PathVariable List<Integer> ids){
        return baseService.delClass(ids);
    }
}
